package com.zhongke.cotrun.service.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhongke.cotrun.service.PayOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhongke.cotrun.common.job.CronJobsUtil;
import com.zhongke.cotrun.mapper.PayOrderMapper;
import com.zhongke.cotrun.model.pojo.PayOrder;

/**
 * @Description: 支付订单信息
 * @Author: songjing
 * @Date:   2020-03-20
 * @Version: V1.0
 */
@Service
public class PayOrderServiceImpl extends ServiceImpl<PayOrderMapper, PayOrder> implements PayOrderService {
	private static final Logger logger = LoggerFactory.getLogger(PayOrderServiceImpl.class);
	@Autowired
	PayOrderMapper payOrderMapper;
	/**
     * 根据orderCode查看订单详情
     *
     * @param 订单号
     * @return
     */
    public PayOrder selectDetailByOrderCode(String orderCode){
    	return payOrderMapper.selectDetailByOrderCode(orderCode);
    }
    /**
     * 根据用户id查看用户订单列表
     * @param userId 用户表主键
     * @param searchKey 关键词
     * @param pageNum 页码
     * @param pageSize 页大小
     * @return
     */
	public PageInfo selectAllByMine(Long userId,String searchKey,String state,String appraiseState, Integer pageNum, Integer pageSize){
		PageHelper.startPage(pageNum, pageSize);
		List<Map> list = payOrderMapper.selectAllByMine(userId,searchKey,state,appraiseState);
		PageInfo pageInfo = new PageInfo(list);
	    return pageInfo;
	}
	/**
     * 根据指定主体主键查看订单列表
     * @param mainId 用户表主键
     * @param type 主体类型
     * @param searchKey 关键词
     * @param pageNum 页码
     * @param pageSize 页大小
     * @return
     */
    public PageInfo selectAllByMain(Long mainId,String type,String searchKey,String state,String appraiseState, Integer pageNum, Integer pageSize){
		PageHelper.startPage(pageNum, pageSize);
		List<Map> list = payOrderMapper.selectAllByMain(mainId, type, searchKey, state, appraiseState);
		PageInfo pageInfo = new PageInfo(list);
	    return pageInfo;
	}
	/**
     * 查询过期未支付订单
     * @return
     */
    public List<PayOrder> selectOutTimeList(){
    	return  payOrderMapper.selectOutTimeListByEndTime();//得到所有超过30分钟 未付款的订单
    }
}